#include "triangle.h"

Triangle::Triangle()
{
    v[0] << 0,0,0;
    v[1] << 0,0,0;
    v[2] << 0,0,0;

    color[0] << 0.0, 0.0, 0.0;
    color[1] << 0.0, 0.0, 0.0;
    color[2] << 0.0, 0.0, 0.0;

    tex_coords[0] << 0.0, 0.0;
    tex_coords[1] << 0.0, 0.0;
    tex_coords[2] << 0.0, 0.0;


}

void Triangle::setVertex(int index, Vector3f vertex)
{
    v[index] = vertex;
}


void Triangle::setNormal(int index, Vector3f n)
{
    normal[index] = n;
}

void Triangle::setColor(int index, float r, float g, float b)
{
    if ((r < 0.0) || (r > 255.) || (g < 0.0) || (g > 255.) || (b < 0.0) ||
       (b > 255.)) {
       throw std::runtime_error("Invalid color values");
   }

   color[index] = Vector3f((float)r / 255., (float)g / 255., (float)b / 255.);
   return;
}

void Triangle::setTexCoord(int index, float s, float t)
{
    tex_coords[index] = Vector2f(s, t);
}

//std::array<Vector4f, 3> Triangle::toVector4() const
//{
//    std::array<Vector4f, 3> res;
////    std::transform(std::begin(v), std::end(v), res.begin(), [](Vector3f& vec) {
////        return Vector4f(vec.x(), vec.y(), vec.z(), 1.f);
////    });
////    for(std::array<Vector4f, 3>::iterator i=res.begin();i!=res.end();i++){

////    }
//    res[0] = Vector4f(this->v[0],1.f);
//    res[1] = Vector4f(this->v[1],1.f);
//    res[2] = Vector4f(this->v[2],1.f);
//    return res;
//}
